package com.itheima06;

/**
 * @author Xiao
 * @date 2021/7/25
 */
public class Student1 implements Comparable<Student1>{
    private String name;
    private int age;
    @Override
    public int compareTo(Student1 o) {
        //主要排序规则：年龄
        if (this.age != o.age) {
            return this.age - o.age;
        }
        //次要排序规则：姓名
        return this.name.compareTo(o.name);
        /*int result = this.age - o.age;
        return result == 0 ? this.name.compareTo(o.name) : result;*/
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public Student1() {
    }

    public Student1(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
